-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSolution.c
More file actions
35 lines (27 loc) · 788 Bytes
/
Solution.c
File metadata and controls
35 lines (27 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>
int longestIncreasingSubsequence(int arr[], int n) {
int lis[n];
for (int i = 0; i < n; i++)
lis[i] = 1;
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++)
if (arr[i] > arr[j] && lis[i] < lis[j] + 1)
lis[i] = lis[j] + 1;
int max = 0;
for (int i = 0; i < n; i++)
if (lis[i] > max)
max = lis[i];
return max;
}
int main() {
int n;
printf("Enter the number of elements: ");
scanf("%d", &n);
int arr[n];
printf("Enter the elements of the array:\n");
for (int i = 0; i < n; i++)
scanf("%d", &arr[i]);
int result = longestIncreasingSubsequence(arr, n);
printf("Length of Longest Increasing Subsequence: %d\n", result);
return 0;
}